package com.niiwoo.civet.account.service.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.account.enums.AccountSendPrizeStatusEnum;
import com.niiwoo.civet.account.service.MarketingAsyncDubboService;
import com.niiwoo.civet.account.service.local.MarketingLocalService;
import com.niiwoo.tripod.lanmao.enums.UserRoleEnum;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.ExecutionException;

@Service(version = "1.0.0")
public class MarketingAsyncDubboServiceImpl implements MarketingAsyncDubboService {

    @Autowired
    MarketingLocalService marketingLocalService;

    @Override
    public void sendPrize(String requestNo , UserRoleEnum userRoleEnum) throws ExecutionException, InterruptedException {

        boolean asyncFlag = marketingLocalService.asyncSendTransaction(requestNo, userRoleEnum);

        AccountSendPrizeStatusEnum sendPrizeStatusEnum = asyncFlag ? AccountSendPrizeStatusEnum.SEND : AccountSendPrizeStatusEnum.SEND_FAILED;

        marketingLocalService.activityOrderStatusChange(requestNo, sendPrizeStatusEnum);

    }

}
